package com.xiaoq.distribution.entity;

import java.io.Serializable;
import java.util.*;

import org.mongodb.morphia.annotations.Entity;

import com.xiaoq.MongoEntity;

@Entity(value="distriTicket",noClassnameStored=true)
public class DistriTicketEntity extends MongoEntity implements Serializable{
	private String agreementId; // 合同Id
	private String type;// 门票类型
	private String shopId; // 景区店铺Id
	private String merchantId; // 景区商家Id
	private String ticketType; //门票类型
	private String ticketId; //门票Id
	private String ticketName; // 门票名称
	private Long prePrice; // 预售价格
	private Long authNum; // 授权数量
	private long refundAuthNum;  //退票数量
	private long commitAuthNum; //用了的数量
	private String reTicket; // 是否退票00可以退票，10不可以退票
	private String balance; // 00 核销后结算，10 下单结算
	private Long distriTicketStart; // 票分销开始日期
	private Long distriTicketEnd; // 票的分销结束日期
	private String distribId;  // 分销商Id
	private String distribName; //分销商名称
	private String status; // 授权票的状态 00 待审核，10 审核成功，20授权失败,30取消授权
	private String failReason; //审核失败的原因
	private List<TicketPrice> ticketPrices; // 门票的授权梯度
	
	
	
	public String getTicketName() {
		return ticketName;
	}
	public void setTicketName(String ticketName) {
		this.ticketName = ticketName;
	}
	public Long getDistriTicketStart() {
		return distriTicketStart;
	}
	public void setDistriTicketStart(Long distriTicketStart) {
		this.distriTicketStart = distriTicketStart;
	}
	public Long getDistriTicketEnd() {
		return distriTicketEnd;
	}
	public void setDistriTicketEnd(Long distriTicketEnd) {
		this.distriTicketEnd = distriTicketEnd;
	}
	
	
	public List<TicketPrice> getTicketPrices() {
		return ticketPrices;
	}
	public void setTicketPrices(List<TicketPrice> ticketPrices) {
		this.ticketPrices = ticketPrices;
	}
	public String getAgreementId() {
		return agreementId;
	}
	public void setAgreementId(String agreementId) {
		this.agreementId = agreementId;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getShopId() {
		return shopId;
	}
	public void setShopId(String shopId) {
		this.shopId = shopId;
	}
	public String getMerchantId() {
		return merchantId;
	}
	public void setMerchantId(String merchantId) {
		this.merchantId = merchantId;
	}
	public String getTicketType() {
		return ticketType;
	}
	public void setTicketType(String ticketType) {
		this.ticketType = ticketType;
	}
	public String getTicketId() {
		return ticketId;
	}
	public void setTicketId(String ticketId) {
		this.ticketId = ticketId;
	}
	public Long getPrePrice() {
		return prePrice;
	}
	public void setPrePrice(Long prePrice) {
		this.prePrice = prePrice;
	}
	public Long getAuthNum() {
		return authNum;
	}
	public void setAuthNum(Long authNum) {
		this.authNum = authNum;
	}
	public String getReTicket() {
		return reTicket;
	}
	public void setReTicket(String reTicket) {
		this.reTicket = reTicket;
	}
	public String getBalance() {
		return balance;
	}
	public void setBalance(String balance) {
		this.balance = balance;
	}
	public String getDistribId() {
		return distribId;
	}
	public void setDistribId(String distribId) {
		this.distribId = distribId;
	}
	public String getDistribName() {
		return distribName;
	}
	public void setDistribName(String distribName) {
		this.distribName = distribName;
	}
	public String getStatus() {
		return status;
	}
	public void setStatus(String status) {
		this.status = status;
	}
	public String getFailReason() {
		return failReason;
	}
	public void setFailReason(String failReason) {
		this.failReason = failReason;
	}

	public long getRefundAuthNum() {
		return refundAuthNum;
	}

	public void setRefundAuthNum(long refundAuthNum) {
		this.refundAuthNum = refundAuthNum;
	}

	public long getCommitAuthNum() {
		return commitAuthNum;
	}

	public void setCommitAuthNum(long commitAuthNum) {
		this.commitAuthNum = commitAuthNum;
	}


	/**
	 * 得到结算价格
	 *  1 表示超过最大的购票数量
	 * @return
	 */
	public long getSettlePrice(long currentCommitAuthNum){
		if(ticketPrices != null){
			//做一次排序
			ticketPrices.sort((item1, item2) -> item1.getMinTickeNum().compareTo(item2.getMinTickeNum()));
			for (TicketPrice ticketPrice : ticketPrices){
				if (currentCommitAuthNum <= ticketPrice.getMaxTickeNum()
						&& ticketPrice.getMinTickeNum() <= currentCommitAuthNum){
					return ticketPrice.getSettlePrice();
				}
			}
			return 1L;
		}
		return 0L;
	}

}
